import axios from './request'

export function get(url: any, params = {}) {
  return new Promise((resolve, reject) => {
    axios
      .get(url, {
        params: params,
      })
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}
// post 请求
export const post = (url: any, data: any) => {
  return new Promise((resolve, reject) => {
    axios
      .post(url, data)
      .then((res) => {
        console.log("resresres",res)
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export function fetch(url: any, params = {}) {
  return new Promise((resolve, reject) => {
    axios
      .get(url, {
        params: params,
      })
      .then((response) => {
        resolve(response)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export function patch(url: any, data = {}) {
  return new Promise((resolve, reject) => {
    axios.patch(url, data).then(
      (response) => {
        console.log('patch', response)
        resolve(response)
      },
      (err) => {
        reject(err)
      },
    )
  })
}

export function put(url, data = {}) {
  return new Promise((resolve, reject) => {
    axios.put(url, data).then(
      (response) => {
        resolve(response)
      },
      (err) => {
        reject(err)
      },
    )
  })
}

export function deletes(url, params) {
  return new Promise((resolve, reject) => {
    axios
      .delete(url, {
        params: params,
      })
      .then((res) => {
        console.log(res)
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}
